namespace Radar
{
    using System;
    using System.Collections.Generic;

    public sealed class ResolveContext
    {
        private readonly IList<string> currentKeysStack = new List<string>();

        internal bool Contains(string key)
        {
            if (key == null) throw new ArgumentNullException("key");

            return currentKeysStack.Contains(key);
        }

        internal void Push(string key)
        {
            if (key == null) throw new ArgumentNullException("key");

            if (currentKeysStack.Contains(key))
                throw new CircularReferenceException(string.Format("Circular reference detected for key '{0}'", key));

            currentKeysStack.Add(key);
        }

        internal void Pop(string key)
        {
            if (key == null) throw new ArgumentNullException("key");

            currentKeysStack.Remove(key);
        }
    }
}